package fiuba.model;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;


import javax.persistence.*;


@Entity
@SqlResultSetMapping(name="implicit", entities=@EntityResult(entityClass=fiuba.model.MenuItem.class))
@NamedNativeQuery(name="menu.menuItemsLeft", query="select * from menuItem m where not exists " +
		"(select * from menu_menuitem where menu_menuitem.menu_id = :menuId " +
		"and menu_menuitem.menuitem_id = m.id)", resultSetMapping="implicit")
public class MenuItem  extends BaseObject{
	private static final long serialVersionUID = 3842626162173359411L;

    private Long id;
    private String name;
    private Seccion seccion;
    private String imagen;
    private String imagenMouseOver;
    
    /**
     * Default constructor - creates a new instance with no values set.
     */
    public MenuItem (){
    	super();
    }
    
	@Id @GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}
    public void setId(Long id) {
		this.id = id;
	}    

    public MenuItem (String name){
    	this.name = name;
    }
    

	public void setName(String name) {
		this.name = name;
	}
	
    @Column(nullable=false,length=50)
	public String getName() {
		return name;
	}
	
	
	
	public void setSeccion(Seccion seccion) {
		this.seccion = seccion;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	public Seccion getSeccion() {
		return seccion;
	}
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = prime * ((seccion == null) ? 0 : seccion.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		final MenuItem other = (MenuItem) obj;
		if (seccion == null) {
			if (other.seccion != null)
				return false;
		} else if (!seccion.equals(other.seccion))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}	
	@Override
	public String toString(){
		ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).		
		    append("Name: ", this.name);
		if (this.seccion != null )
		    sb = sb.append("Content: ", this.seccion.toString());
		return sb.toString();
	}

	@Column
	public String getImagen() {
		return imagen;
	}

	public void setImagen(String imagen) {
		this.imagen = imagen;
	}
	
    @Column
	public String getImagenMouseOver() {
		return imagenMouseOver;
	}

	public void setImagenMouseOver(String imagenMouseOver) {
		this.imagenMouseOver = imagenMouseOver;
	}
	
	
}
